
import 'package:flutter/cupertino.dart';
import 'package:flutter_li_ke_jie/constant/api_constant.dart';
import 'package:flutter_li_ke_jie/core/http/http.dart';
import 'package:flutter_li_ke_jie/core/utils/toast.dart';
import 'package:flutter_li_ke_jie/entity/app_product.dart';
import 'package:flutter_li_ke_jie/utils/sputil.dart';

import '../../entity/app_product_list.dart';
import '../../utils/log.dart';

//产品model
class ProductModel with ChangeNotifier{
  List<AppProduct> products = [];
  List<AppProduct> jiSuDaiProducts = [];

  //获取产品列表
  void getProductList(){
    int? vipState = SPUtil.getVipState();
    //不是vip查询的时候需要加上
    Map<String,dynamic> map = {
      "pageNum":1,
      "pageSize":100
    };
    if(vipState==null||vipState==0){
      map["isVip"] = 0;
    }
    XHttp.get(ALL_PRODUCT_LIST,map).then((response){
      Log.e("获取产品列表${response}");
      if(response["code"]==200){
        AppProductList appProductList = AppProductList.fromJson(response);
        //数据解析
        if(appProductList!=null){
          products = appProductList.appProduct!;
        }
        notifyListeners();
      }else{
        ToastUtils.error(response["msg"]);
      }
    });
  }


  //极速贷获取产品列表
  void getJiSuDaiProductList(){
    //不是vip查询的时候需要加上
    Map<String,dynamic> map = {
      "pageNum":1,
      "pageSize":8
    };
    XHttp.get(ALL_PRODUCT_LIST,map).then((response){
      Log.e("获取极速贷产品列表${response}");
      if(response["code"]==200){
        AppProductList appProductList = AppProductList.fromJson(response);
        //数据解析
        if(appProductList!=null){
          jiSuDaiProducts = appProductList.appProduct!;
        }
        notifyListeners();
      }else{
        ToastUtils.error(response["msg"]);
      }
    });
  }
}